﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Pixysoft.Framework.Verifications;

namespace Pixysoft.Weblications.Sango
{
    class ContentReviewHelper
    {
        private static BadWordHelper helper = null;

        public static void Initialize()
        {
            //string filename = default_config_basepath + StringHelper.sango_filename_badword;

            //if (!File.Exists(filename))
            //    throw Exceptions.VerificationFailedException();

            //string content = File.ReadAllText(filename);

            //helper = new BadWordHelper(content);

            helper = new BadWordHelper("");
        }

        private static string default_config_basepath
        {
            get
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;

                if (!path.EndsWith(@"\"))
                    return path + @"\";
                else
                    return path;
            }
        }


        internal static string Replace(string value, int length)
        {
            if (value.Length > length)
                value = value.Substring(0, length);

            value = helper.replaceBadWord(value);

            StringBuilder builder = new StringBuilder();

            regularLogContent(builder, value);

            return builder.ToString();
        }

        private static void regularLogContent(StringBuilder builder, string log)
        {
            if (string.IsNullOrEmpty(log))
            {
                return;
            }

            foreach (char ch in log)
            {
                if (ch == '<')
                {
                    builder.Append("&lt;");
                }
                else if (ch == '>')
                {
                    builder.Append("&gt;");
                }
                else
                {
                    builder.Append(ch);
                }
            }

        }
    }
}